/*
 * @Author: WangShuai 1830773767@qq.com
 * @Date: 2025-06-29 16:20:25
 * @LastEditors: WangShuai 1830773767@qq.com
 * @LastEditTime: 2025-06-29 18:17:46
 * @FilePath: \shangyitong\src\permission.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
//路由鉴权就是路由能不能被访问到权限设置 ==>全局守卫完成
import router from '@/router/index'
import nProgress from 'nprogress'
//引入大仓库
import pinia from '@/store'
import useUserStore from '@/store/modules/user'
let userStore = useUserStore(pinia)
//进度条隐藏加载小圆球样式
nProgress.configure({ showSpinner: false })
import 'nprogress/nprogress.css'
//用户未登录可以访问的路由路径
let whiteList = [
'/home',
'/hospital/register',
'/hospital/detail',
'/hospital/notice',
'/hospital/close',
'/hospital/search'
]
//全局前置守卫
//@ts-ignore
router.beforeEach((to, from, next: any,) => {
    nProgress.start()  //开始播放进度条动画
    //动态设置页签标题
    document.title = `尚医通-${to.meta.title}`;   
    let token = userStore.userInfo.token;
    if (token) {
        next()
    }else{
        //用户未登录可以访问的路由路径
        if(whiteList.includes(to.path)){
            next()
        }else{
            //显示登录组件
            userStore.visible = true;
            next({path:"/home",query:{
                redirect:to.fullPath
            }})
        }
    }

})
//全局后置守卫
router.afterEach((to, from, next: any) => {
    nProgress.done()   //结束播放进度条动画
})